feat(core): Pass normalizedRequest to the sampling context for root spans#21833
Merged
Conversation
…pans Forward the isolation scope's normalizedRequest into the tracesSampler sampling context for root spans, so sampling functions can decide based on the incoming request (url, method, query string). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
chargome
approved these changes
Jun 29, 2026
nicohrubec
approved these changes
Jun 29, 2026
Contributor
size-limit report 📦
|
49 tasks
6 tasks
sergical
added a commit
to getsentry/sentry-docs
that referenced
this pull request
Jul 14, 2026
…10.65 The docs tracesSampler classifies traffic (AI agent / bot / user) to sample accordingly and emit the docs.trace.sampled metric, but @sentry/core did not pass normalizedRequest into the sampling context for root spans until 10.63.0 (getsentry/sentry-javascript#21833). On the previous 10.55.0 that field was always undefined, so all traffic fell through to "unknown": AI-agent traces were under-sampled, bot noise wasn't filtered, and the metric couldn't segment traffic. - Bump @sentry/nextjs and @sentry/browser to 10.65.0 (within the existing ^10 range); consolidates the previously split @sentry/core versions. - Consolidate classification into a single user-agent-based classifyFromHeaders, used by both the tracesSampler and a new span attribute. - Tag every root span with docs.traffic_type so classification is queryable on spans, which flush from every environment (the metric only flushes reliably under sustained production traffic). - Remove the middleware x-traffic-type/x-device-type request-header injection and the sampler's header-classification path: the injected headers never reached the sampler (middleware transactions sample off the incoming request; route handlers carry no normalized request), so that machinery was dead. Co-Authored-By: Claude <noreply@anthropic.com>
sergical
added a commit
to getsentry/sentry-docs
that referenced
this pull request
Jul 14, 2026
Fixes docs traffic classification. The tracesSampler reads samplingContext.normalizedRequest to classify traffic (AI agent / bot / user) and sample accordingly, but @sentry/core did not populate normalizedRequest in the sampling context for root spans until 10.63.0 (getsentry/sentry-javascript#21833). On the previous 10.55.0 that field was always undefined, so all traffic was classified "unknown": agent traces under-sampled, bots not filtered, and docs.trace.sampled unable to segment. No code changes needed — the existing sampler works once the SDK populates the field. Also consolidates the previously split @sentry/core versions onto 10.65. Co-Authored-By: Claude <noreply@anthropic.com>
sergical
added a commit
to getsentry/sentry-docs
that referenced
this pull request
Jul 15, 2026
## DESCRIBE YOUR PR Bumps `@sentry/nextjs` and `@sentry/browser` to `10.65.0` (within the existing `^10` range) to fix docs traffic classification, which was silently broken. `src/tracesSampler.ts` reads `samplingContext.normalizedRequest` to classify traffic as AI agent / bot / user and sample accordingly (agents 100%, bots 0%, users 30%), emitting the `docs.trace.sampled` metric. But `@sentry/core` did not populate `normalizedRequest` in the sampling context for root spans until **10.63.0** ([getsentry/sentry-javascript#21833](getsentry/sentry-javascript#21833)). On the resolved `10.55.0` that field was always `undefined`, so all traffic was classified `unknown`: agent traces were under-sampled, bot noise wasn't filtered, and the metric couldn't segment traffic. **No code changes** — the existing sampler works as designed once the SDK populates the field. Verified on a preview deploy that `10.65.0` populates the sampler's `normalizedRequest` (with the user-agent) on the real Vercel runtime; the metric will show the correct `ai_agent`/`bot`/`user` breakdown in production once deployed. - Bump `@sentry/nextjs` + `@sentry/browser` to `^10.65.0` - Consolidates the previously split `@sentry/core` versions onto `10.65.0` ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Forward the isolation scope's
normalizedRequestinto thetracesSamplersampling context for root spans._startRootSpannow includes it in the object passed to the sampler.Why
SamplingContextalready advertises anormalizedRequestfield, and server SDKs already record the incoming request on the isolation scope, but core never wired the two together for root spans, sotracesSampleralways receivednormalizedRequest: undefinedon the standard root-span path. This closes that gap so custom samplers can decide based on the incoming request (drop health-check routes, raise the rate for/api/*, key off the HTTP method) instead of reverse-engineering it from the span name or attributes, which for an incoming HTTP root span may not yet carry the route at sampling time.Extracted standalone from #21666 (the
SentryTracerProviderstack): it has no dependency on that work, ships on its own merits, and shrinks #21666's review surface.